public class T {
}




 class ListNode {
     int val;
     ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

class Solution {
    public ListNode removeElements(ListNode head, int val) {
        if(head==null){
            return null;
        }

        ListNode next=head.next;
        ListNode slow=head;

        while(next!=null){
            if(next.val==val){
                slow.next=next.next;
                next=slow.next;

            }else {
                next=next.next;
                slow=slow.next;
            }
        }
        if(head.val==val){

            head=head.next;
        }

        return head;





    }
}